home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tas412.zip / PA1A.INC < prev    next >
Text File  |  1991-10-26  |  7KB  |  201 lines

  1. {
  2.    This script contains the "Achelis Binary Wave(tm)" calculation
  3.    shown in the Metastock(*) 2.0 distribution system. It has been
  4.    modified to include the following indicators as well:
  5.                                     BUY         SELL
  6.       Chaikin's Oscillator          > 0         < 0
  7.       Parabolic SAR                 < C         > C
  8.       Commodity Channel Index      > 100       < -100
  9.    It is here to give an example of the kind of analysis
  10.    available with the TAS Script language.
  11.    The Metastock manual discusses this binary wave system on
  12.    page 187 of the User's Manual.
  13.    The script will put out a message if the value of the binary
  14.    wave changes from yesterday to today (the terms 'today' and
  15.    'yesterday' are used loosely, but meant to be the 'latest day'
  16.    and the 'day before', respectively).
  17.    Two variables are defined and updated as each of the four
  18.    individual binary wave formulas are checked.
  19.    They are:
  20.    "t_bwave" which is today's binary wave value (-7 to +7)
  21.             and
  22.    "y_bwave" which is yesterday's binary wave value (-7 to +7)
  23.    What we are looking for is a TRANSITION from yesterday to
  24.    today. If the stock moved to +7 today and it was lower yesterday,
  25.    perhaps this is a buying opportunity. If the stock moved to -7
  26.    perhaps it is a short sell.
  27. }
  28.  
  29. { This subroutine takes a variable PERIOD as the number of days to 
  30.   look back in computing "y_bwave" }
  31.  
  32. :BinaryWave
  33. lb = -period;            { Compute "look back" index }
  34. y_total : number;        { yesterday's total bwave }
  35. t_total : number;        { today's total bwave value }
  36. c_total : number;        { total changed bwave values}
  37. tick_total : number;     { ticker count }
  38. sell_count : number;     { total SELL's given }
  39. buy_count : number;      { total BUY's given }
  40. MACD_ARRAY : ARRAY;    { Place to put values for TODAY }
  41. MACDTRIG_ARRAY : ARRAY;
  42. MA20 : ARRAY;
  43. ROC12 : ARRAY;           { PLACE TO PUT RATE OF CHANGE }
  44. STOCH53 : ARRAY;                { PLACE TO PUT STOCH(5,3) VALUES }
  45. CO_ARRAY : ARRAY;
  46. CCI14 : ARRAY;          { PLACE TO PUT CCI(14) VALUES }
  47. SAR_A : ARRAY;          { PARABOLIC SAR ARRAY}
  48. y_bwave := 0;     { this is our 'score' yesterday}
  49. t_bwave := 0;     { this is our 'score' today}
  50. alert   := '         ';
  51. if FIRST_TICKER then
  52. begin
  53.     y_total = 0;        { yesterday's total bwave }
  54.     t_total = 0;        { today's total bwave value }
  55.     c_total = 0;        { total changed bwave values}
  56.     tick_total = 0;     { ticker count }
  57.     sell_count = 0;     { SELL count }
  58.     buy_count = 0;      { BUY count }
  59. end;
  60. BEGIN
  61.     {
  62.        First compute MACD Binary Wave for yesterday and today
  63.        Note that MACD() computes the 12 day EMA - 26 day EMA and places
  64.        the result in the array MACD_ARRAY. The 9 day EMA is computed
  65.        and placed in the result array MACDTRIG_ARRAY
  66.     }
  67.     MACD_ARRAY = MACD();
  68.     MACDTRIG_ARRAY = MACDTRIGGER();
  69.     {
  70.        Now compute 20-MA B-Wave
  71.     }
  72.     MA20 := mov(c,20,'E');   { Compute 20 unit EMA of close }
  73.     {
  74.        Now compute 12-ROC B-Wave
  75.     }
  76.     ROC12 := roc(c,12,'%');
  77.     {
  78.        Now compute 5-3 stochastic B-wave
  79.     }
  80.     STOCH53 := stoch(5,3);          { compute stoch(%K period, %K slow) }
  81.     {
  82.         check if Chaikin's AD oscillator is above or below 0
  83.     }
  84.     CO_ARRAY := CO();       { PLACE CHAIKIN'S OSCILLATOR IN CO_ARRAY}
  85.     {
  86.         check if CCI(14)  above +100 or below -100
  87.     }
  88.     CCI14 := cci(14);
  89.     {
  90.        check if Wilder's Parabolic is greater or less than close
  91.     }
  92.     SAR_A := SAR(.02,.20);
  93.  
  94.    { All arrays are calculated. Now do the checking of change }
  95.     IF MACD_ARRAY[0] > MACDTRIG_ARRAY[0] THEN
  96.        t_bwave := t_bwave + 1    { macd greater than trigger }
  97.     else
  98.        t_bwave := t_bwave - 1;   { macd less than trigger    }
  99.     if MACD_ARRAY[lb] > MACDTRIG_ARRAY[lb] then
  100.        y_bwave := y_bwave + 1    { macd greater than trigger }
  101.     else
  102.        y_bwave := y_bwave - 1;   { macd less than trigger    }
  103.     if c[0] > MA20 then    { compare today's close to today's ema}
  104.        t_bwave := t_bwave + 1    { ema greater than close }
  105.     else
  106.        t_bwave := t_bwave - 1;   { ema less than close    }
  107.    { compare yesterday's close to today's ema}
  108.     if c[lb] > MA20[lb] then 
  109.        y_bwave := y_bwave + 1    { ema greater than close }
  110.     else
  111.        y_bwave := y_bwave - 1;   { ema less than close    }
  112.     if ROC12 > 0 then
  113.        t_bwave := t_bwave + 1    { roc greater than 0 }
  114.     else
  115.        t_bwave := t_bwave - 1;   { roc less than 0    }
  116.     if ROC12[lb] > 0 then
  117.        y_bwave := y_bwave + 1    { roc greater than 0 }
  118.     else
  119.        y_bwave := y_bwave - 1;   { roc less than 0    }
  120.     if STOCH53[0] > 50 then
  121.        t_bwave := t_bwave + 1    { stoch greater than 50 }
  122.     else
  123.        t_bwave := t_bwave - 1;   { stoch less than 50    }
  124.     if STOCH53[lb] > 50 then
  125.        y_bwave := y_bwave + 1    { stoch greater than 50 }
  126.     else
  127.            y_bwave := y_bwave - 1;   { stoch less than 50    }
  128.     IF CO_ARRAY[0] > 0 THEN
  129.         t_bwave := t_bwave + 1
  130.     else
  131.         t_bwave := t_bwave - 1;
  132.     IF CO_ARRAY[lb] > 0 THEN
  133.         y_bwave := y_bwave + 1
  134.     else
  135.         y_bwave := y_bwave - 1;
  136.     if CCI14[0] < -100 then
  137.        t_bwave := t_bwave - 1
  138.     else
  139.     if CCI14[0] > 100 then
  140.        t_bwave := t_bwave + 1;
  141.     if CCI14[lb] < -100 then
  142.        y_bwave := y_bwave - 1
  143.     else
  144.     if CCI14[lb] > 100 then
  145.        y_bwave := y_bwave + 1;
  146.     if SAR_A[0] > C then    { if SAR above close, position is SHORT}
  147.        t_bwave := t_bwave-1
  148.     else
  149.        t_bwave := t_bwave+1;
  150.     if SAR_A[lb] > C[lb] then    { if SAR above close, position is SHORT}
  151.        y_bwave := y_bwave-1
  152.     else
  153.        y_bwave := y_bwave+1;
  154.     {
  155.        Okay, here we are at the end of the script. We have boiled
  156.        the formulas down to two values:
  157.        "t_bwave" which is today's binary wave value (-7 to +7)
  158.                 and
  159.        "y_bwave" which is yesterday's binary wave value (-7 to +7)
  160.     }
  161.     {
  162.        First, let's check if the wave moved to +7..if so, let's print
  163.        out it's value then and now
  164.     }
  165.     tick_total = tick_total + 1;    { add to count of tickers }
  166.     y_total = y_total + y_bwave;    { add yesterday's bwave to total}
  167.     t_total = t_total + t_bwave;    { add today's bwave to total}
  168.     c_total = c_total + diff;    { add diff in bwave to total}
  169.     buy_flag = 0;
  170.     sell_flag = 0;
  171.     alert = '         ';
  172.     if ((y_bwave < 7) and (t_bwave = 7)) then
  173.     begin
  174.         buy_flag = 1;
  175.         alert = '   BUY   ';
  176.         buy_count = buy_count + 1;
  177.     end
  178.     {
  179.        Now, let's check if the wave moved to -7..if so, let's print
  180.        out it's value then and now
  181.     }
  182.     else
  183.     if ((y_bwave > -7) and (t_bwave = -7)) then
  184.     begin
  185.         sell_flag =  1;
  186.         alert = '   SELL  ';
  187.         sell_count = sell_count + 1;
  188.     end;
  189. END;     { of if good_date = date }
  190. RETURN;
  191. if last_ticker then
  192. begin
  193.    writeln('\t\t\n\n------------- SUMMARY--------------------');
  194.    writeln('\tTickers Processed             ',INT(tick_total));
  195.    writeln('\tYesterday Binary Wave Average ',y_total/tick_total);
  196.    writeln('\tToday Binary Wave Average     ',t_total/tick_total);
  197.    writeln('\tAverage Change in Binary Wave ',c_total/tick_total);
  198.    writeln('\t',INT(buy_count),' BUY Signals');
  199.    writeln('\t',INT(sell_count),' SELL Signals');
  200. end;
  201.